package com.example.permission.mapper;

import com.example.permission.entity.SystemRole;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author qwer3
 * @version 1.0.0
 * @create 2025/11/16 11:31
 */
@Mapper
public interface SystemRoleMapper {
    @Insert("""
insert into sys_role (role_id, name, description, create_time, update_time, is_delete) 
values (#{roleId}, #{name}, #{description}, now(), now(), 0) 
ON DUPLICATE KEY UPDATE
    name = VALUES(name),
    description = VALUES(description),
    update_time = now()
""")
    void saveOrModifyRole(SystemRole systemRole);

    @Select("""
select * from sys_role where role_id = #{roleId}
""")
    SystemRole querySystemRoleByRoleId(String roleId);


    @Select("""
select * from sys_role where is_delete = 0
""")
    List<SystemRole> querySystemRoleList();

    @Update("""
update sys_role set is_delete = 1 where role_id = #{roleId}
""")
    void deleteRoleByRoleId(String roleId);

    @Select("""
select * from sys_user_role ur left join sys_role r on ur.role_id = r.role_id
where ur.user_id = #{userId}
""")
    SystemRole queryRoleByUserId(String userId);
}
